prometheus-node-exporter-lua: remove zero values
authorMarkus Hube <[email protected]>
Sat, 22 Nov 2025 09:47:35 +0000 (10:47 +0100)
committerTianling Shen <[email protected]>
Tue, 9 Dec 2025 00:14:54 +0000 (08:14 +0800)
depending on the configuration there may be multiple
interfaces creating multiple time series always
reporting 0 value. omiting them from the export saves
resources. most notably cpu. this is limited to
counter types

Signed-off-by: Markus Hube <[email protected]>
utils/prometheus-node-exporter-lua/Makefile
utils/prometheus-node-exporter-lua/files/etc/init.d/prometheus-node-exporter-lua
utils/prometheus-node-exporter-lua/files/usr/bin/prometheus-node-exporter-lua

index f043212156bf155079b83fc494d5f7b9c5ef7318..37c6f7d1bee3774c9159fee910021bc555b572ad 100644 (file)
@@ -4,7 +4,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=prometheus-node-exporter-lua
-PKG_VERSION:=2025.07.15
+PKG_VERSION:=2025.11.22
 PKG_RELEASE:=1
 
 PKG_MAINTAINER:=Etienne CHAMPETIER <[email protected]>
index 154ce13539f9a65cb2407643c3615d9c11ecb5fa..3b67675fcc83af83757d5aa963b25c53229d2c23 100644 (file)
@@ -11,7 +11,7 @@ _log() {
 start_service() {
        . /lib/functions/network.sh
 
-       local interface port listenflag cert key bind4 bind6
+       local interface port listenflag cert key bind4 bind6 omit_zero_values
 
        config_load prometheus-node-exporter-lua.main
        config_get keepalive "main" http_keepalive 70
@@ -19,6 +19,7 @@ start_service() {
        config_get port "main" listen_port 9100
        config_get cert "main" cert
        config_get key "main" key
+       config_get omit_zero_values "main" omit_zero_values 0
 
        [ "$interface" = "*" ] || {
                network_get_ipaddr  bind4 "$interface"
@@ -31,6 +32,8 @@ start_service() {
 
        procd_open_instance
 
+       [ "$omit_zero_values" -eq 1 ] && procd_set_param env OMIT_ZERO_VALUES=1
+
        procd_set_param command /usr/sbin/uhttpd -f -c /dev/null -l / -L /usr/bin/prometheus-node-exporter-lua
        [ $keepalive -gt 0 ] && procd_append_param command -k $keepalive
 
index 2aab28179cb6f52208022476f016734f67b76280..93ecc954e9bb5b4b03ba0fca792b7f39643e8aca 100755 (executable)
@@ -8,6 +8,10 @@
 
 socket = require("socket")
 
+-- get configs
+
+local omit_zero_values = os.getenv("OMIT_ZERO_VALUES") == "1"
+
 -- Parsing
 
 function space_split(s)
@@ -50,8 +54,12 @@ end
 
 function metric(name, mtype, labels, value)
   out:write("# TYPE ", name, " ", mtype, "\n")
+  -- omit_zero_vales config supress time series always being zero
+  local printall = not (mtype == "counter" and omit_zero_values)
   local outputter = function(labels, value)
-    print_metric(name, labels, value)
+    if printall or tonumber(value) ~= 0 then
+      print_metric(name, labels, value)
+    end
   end
   if value then
     outputter(labels, value)